﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_UserControl_form_edit_file_text : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            xGetListFile();
        }
    }

    /// <summary>
    /// Lấy danh sách tất cả các file
    /// </summary>
    private void xGetListFile()
    {
        grvLstFile.DataSource = OsPortal.oFileHelper.fncGetLstFileFromFolder("*.txt", "~/SaveFile/");
        grvLstFile.DataBind();
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grvLstFile_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string strFileName = grvLstFile.Rows[e.NewEditIndex].Cells[0].Text;
        string strFolderName = grvLstFile.Rows[e.NewEditIndex].Cells[2].Text;
        string strUrl = strFolderName + "/" + strFileName;
        lblFileNameEdit.Text = strFileName;
        hdLink.Value = strUrl;
        txtNoiDung.Text = OsPortal.oFileHelper.ReadFile(strUrl);
        lblFileNameEdit.Focus();
        e.Cancel = true;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strPath = "~/" + hdLink.Value;
        OsPortal.oFileHelper.WriteFile(Server.HtmlDecode(txtNoiDung.Text), strPath);
        xGetListFile();
    }
}